using UnityEngine;
using System.Collections;
using Holoville.HOTween;

public class CameraTween : MonoBehaviour{
	
	public Player player;
	public Transform bank;
	
	private bool _started;
	
	protected void Start(){
		_started = false;
		player.locked = true;
		Invoke("TweenStart",0.5f);
	}
	private void TweenStart(){
		_started = true;
		transform.position = player.transform.position+player.cameraOffset;
		
		Vector3 tv = bank.transform.position+player.cameraOffset;
		tv.z = player.transform.position.z+player.cameraOffset.z;
		
		TweenParms tp = new TweenParms();
		tp.Delay(0.8f);
		tp.Prop("position",tv);
		tp.Ease(EaseType.EaseInOutSine);
		tp.OnComplete(Tween1Complete);
		HOTween.To(transform,3f,tp);
	}
			
	private void Tween1Complete(){
		TweenParms tp = new TweenParms();
		tp.Delay(0.5f);
		tp.Prop("position",player.transform.position+player.cameraOffset);
		tp.Ease(EaseType.EaseInOutSine);
		tp.OnComplete(Tween2Complete);
		HOTween.To(transform,3f,tp);
	}
	private void Tween2Complete(){
		player.locked = false;
		this.enabled = false;
	}
	
	protected void Update(){
		if(!_started) transform.position = player.transform.position+player.cameraOffset;
	}
}

